%% Author: vivimice
%% Created: Jan 11, 2012
%% Description: TODO: Add description to utils
-module(utils).

%%
%% Include files
%%

%%
%% Exported Functions
%%
-export([get_process_name/1, floor/1, ceiling/1, min/2, max/2]).

%%
%% API Functions
%%
get_process_name(Pid) ->
	case process_info(Pid, registered_name) of
		{registered_name, Name} ->
			Name;
		_ ->
			Pid
	end.

floor(X) when X < 0 ->
    T = trunc(X),
    case X - T == 0 of
        true -> T;
        false -> T - 1
    end;
floor(X) -> 
    trunc(X).

ceiling(X) when X < 0 ->
    trunc(X);
ceiling(X) ->
    T = trunc(X),
    case X - T == 0 of
        true -> T;
        false -> T + 1
    end.

max(X, Y) when X > Y ->
	X;
max(_, Y) ->
	Y.

min(X, Y) when X < Y ->
	X;
min(_, Y) ->
	Y.
%%
%% Local Functions
%%

